import {AfterViewInit, Component, OnDestroy, OnInit} from '@angular/core';
import { NzModalService, NzMessageService } from 'ng-zorro-antd';
import { HttpService } from '@core/services/http.service';
import {ServerSocket} from "@core/services/ws.service";
import {Subscription} from "rxjs/Subscription";
import {Router} from "@angular/router";
@Component({
  selector: 'app-index',
  templateUrl: './index.component.html',
  styleUrls: ['./index.component.less']
})
export class IndexComponent implements OnInit, OnDestroy, AfterViewInit {

    _loading = false;
    Aname;
    Adetail
    AnnouncementData = [];
    data: any = {
        salesData: []
    };
    loading = true;
    q: any = {
        start: null,
        end: null
    };
    rankingListData = [
        {name: '北京地铁事件'},
        {name: '三星，苹果屏幕炸裂'},
        {name: '深圳山体滑坡'},
        {name: '苏州多塑胶跑道被报有毒'},
        {name: '深圳一工业园山体滑坡'},
        {name: '三星，苹果屏幕炸裂'},
        {name: '深圳山体滑坡'},
        {name: '北京地铁事件'},
        {name: '三星，苹果屏幕炸裂'},
        {name: '北京地铁事件'},
        {name: '苏州多塑胶跑道被报有毒'},
        {name: '深圳一工业园山体滑坡'},
        {name: '北京地铁事件'},
        {name: '深圳一工业园山体滑坡'},
        {name: '北京地铁事件'},
        {name: '三星，苹果屏幕炸裂'}
    ]

    info(contentTpl, data) {
        this.Aname = data.Title;
        this.Adetail = data.Content;
        this.confirmServ.info({
            title: '查看详情',
            okText: '确定',
            content: contentTpl
        });
    }

    AnnouncementList () {
        let param = {};
        this._loading = true;
        this.http.noticeList(param).subscribe(res => {
            this._loading = false;
            this.AnnouncementData = res.list;
        });
    }

    private socketSubscription: Subscription
    ngOnInit() {

       this.AnnouncementList ();
        setTimeout(() => {
            this.data.salesData = [
                {x: '北京', y: 1520},
                {x: '上海', y: 1403},
                {x: '广东', y: 1200},
                {x: '河北', y: 1015},
                {x: '黑龙江', y: 998},
                {x: '四川', y: 920},
                {x: '宁夏', y: 856},
                {x: '新疆', y: 680},
                {x: '天津', y: 501},
                {x: '山东', y: 320}
            ];
            this.loading = false;
        }, 500);



        // send message to server, if the socket is not connected it will be sent
        // as soon as the connection becomes available thanks to QueueingSubject
        // this.ws.send('hello')

    }
    constructor(public msg: NzMessageService,
                private confirmServ: NzModalService,
                private http: HttpService,
                private ws: ServerSocket,
                public router: Router
) {}

    ngAfterViewInit() {
        this.ws.connect();
    }

    ngOnDestroy() {

    }
}
